<template>
	<view>
		<view class="title">
				
			<view class="top">
				<text class="back"  @click="goback">
					{{'<'}}
				</text>
				<view class="name">
					我的会员
				</view>
			</view>
			<view class="bottom">
				<view class="avait">
					<image src="../../static/img/yonghu2@2x.png" mode=""></image>
					<image src="../../static/img/yonghu3@2x.png" mode=""></image>
					<image src="../../static/img/yonghu4@2x.png" mode=""></image>
					<image src="../../static/img/yonghu5@2x.png" mode=""></image>
					<image src="../../static/img/yonghu6@3x.png" mode=""></image>
					<text>44564人开通会员</text>
				</view>
				<text>购买查询</text>
			</view>
		</view>
		<view class="card">
			<view class="img">
				<image src="../../static/img/zu428@2x.png" mode=""></image>
			</view>
			<view class="login">
				<view class="vip-login">
					<h1>立即登录</h1>
					<text>会员</text>
				</view>
				<view class="vip-msg">
					开通会员尊享VIP权益
				</view>
			</view>
		</view>
		<view class="buyVip">
			<view :class="{'VipItem':true,'active':vip==45}" @click="buyVip(45,'12')">
				<h1>12个月</h1>
				<p>￥45</p>
				<h2>￥144</h2>
				<text>推荐</text>
			</view>
			<view :class="{'VipItem':true,'active':vip==18}" @click="buyVip(18,'3')">
				<h1>3个月</h1>
				<p>￥18</p>
				<h2>￥36</h2>
			</view>
			<view :class="{'VipItem':true,'active':vip==8}" @click="buyVip(8,'1')">
				<h1>1个月</h1>
				<p>￥8</p>
				<h2>￥14</h2>
			</view>
		</view>
		<view class="getVip">
			<view class="top">
				<h1>恭喜</h1>
				<text>你获得2折开通会员特权！</text>
			</view>
			<button  @click="open">立即开通</button>
		</view>
		<view class="privilege">
			<h1>VIP特权</h1>
			<view class="item">
				<view class="item-img">
					<image src="../../static/img/ad.png" mode=""></image>
				</view>
				<view class="item-msg">
					<h2>1000+精品名厨菜谱</h2>
					<p>大咖教学，轻松学会</p>
				</view>
			</view>
			<view class="item">
				<view class="item-img">
					<image src="../../static/img/ad.png" mode=""></image>
				</view>
				<view class="item-msg">
					<h2>1000+精品名厨菜谱</h2>
					<p>大咖教学，轻松学会</p>
				</view>
			</view>
			<view class="item">
				<view class="item-img">
					<image src="../../static/img/ad.png" mode=""></image>
				</view>
				<view class="item-msg">
					<h2>1000+精品名厨菜谱</h2>
					<p>大咖教学，轻松学会</p>
				</view>
			</view>
			<view class="item">
				<view class="item-img">
					<image src="../../static/img/ad.png" mode=""></image>
				</view>
				<view class="item-msg">
					<h2>1000+精品名厨菜谱</h2>
					<p>大咖教学，轻松学会</p>
				</view>
			</view>
		</view>
		<view class="explain">
			<h1>会员使用说明</h1>
			<p>1.会员服务—经开通,不支持退款?</p>
			<p>2.如遇到苹果手机支付问题，建议参考Apptore支付5pt流程;</p>
			<p>3.若会员开通出现异常，请立即联系客服，我们会在2个工作日内出处理结果。</p>
			<p>4.会品堂见问颗会品服务协议会品隐利、协议</p>
		</view>
		<view>
			<!-- <button @click="open">打开弹窗</button> -->
			<uni-popup ref="popup" type="bottom">
				<view class="module">
					<h1>开通vip会员</h1>
					<view class="buyVip">
						<view :class="{'VipItem':true,'active':vip==45}" @click="buyVip(45,'12')">
							<h1>12个月</h1>
							<p>￥45</p>
							<h2>￥144</h2>
							<text class="news">即将涨价</text>
						</view>
						<view :class="{'VipItem':true,'active':vip==18}" @click="buyVip(18,'3')">
							<h1>3个月</h1>
							<p>￥18</p>
							<h2>￥36</h2>
						</view>
						<view :class="{'VipItem':true,'active':vip==8}" @click="buyVip(8,'1')">
							<h1>1个月</h1>
							<p>￥8</p>
							<h2>￥14</h2>
						</view>
					</view>
					<view class="getVip">
						<view class="top">
							<h1>恭喜</h1>
							<text class="news">开通后立即全站去广告、免费看10000+名厨视频</text>
						</view>
						<button @click="topay">立即购买</button>
					</view>
					<view class="close" @click="close">
						X
					</view>
				</view>
			</uni-popup>
			<!-- <text ref='qwe'></text> -->
		</view>
	</view>

</template>

<script>
	import {getVipApi} from "@/apis/vip.js"
	import {getUserInfoApi} from "@/apis/mine.js"
	export default {
		data() {
			return {
				vip: 45,
				month:'12'
			};
		},
		methods: {
			buyVip(val,mon) {
				this.vip = val
				this.month=mon
			},
			open() {
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open()


			},
			close() {
				this.$refs.popup.close()
			},
			goback(){
				uni.navigateBack()
			},
			topay(){
				let userinfo=uni.getStorageSync('userinfo')
				let token=uni.getStorageSync('token')
				console.log(userinfo);
				let obj={
					data:{
						_id:userinfo._id,
						date:this.month
					}
				}
				getVipApi(obj).then(res=>{
					console.log(res);
					getUserInfoApi(token).then(val=>{
						console.log(val);
						uni.setStorageSync("userinfo",val[0]);
					})
				})
				uni.navigateTo({
					url:`/pages/payment/payment?price=${this.vip}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		width: 100%;
		height: 508rpx;
		background: url('../../static/img/ditu2@2x.png');
		background-size: contain;
		padding: 100rpx 32rpx 0 0;
		box-sizing: border-box;

		.top {
			margin-bottom: 30rpx;
			width: 100%;
			text-align: center;
			position: relative;
			.name {
				color: white;
			}
			.back{
				position: absolute;
				top: 0;
				left: 48rpx;
				color: white;
			}
		}

		.bottom {
			display: flex;
			justify-content: space-between;

			.avait {
				width: 434rpx;
				height: 48rpx;
				background-color: rgba(0, 0, 0, .3);

				image {
					width: 36rpx;
					height: 36rpx;
					vertical-align: middle;
				}

				text {
					color: white;
					font-size: 24rpx;
				}
			}

			text {
				color: white;
			}
		}
	}

	.card {
		width: 100%;
		height: 300rpx;
		background: url("../../static/img/huiyuan108.png");
		background-size: contain;
		margin-top: -260rpx;
		padding: 80rpx 0 0 64rpx;
		box-sizing: border-box;
		display: flex;

		.img {
			width: 108rpx;
			height: 108rpx;
			margin-right: 18rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.login {
			.vip-login {
				display: flex;
				align-items: center;

				h1 {
					font-size: 48rpx;
					color: #82642A;
					margin-right: 10rpx;
				}

				text {
					width: 106rpx;
					height: 32rpx;
					background-color: gray;
					color: white;
					border-radius: 16rpx;
					text-align: center;
					line-height: 32rpx;
				}
			}
		}
	}

	.buyVip {
		width: 100%;
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		gap: 16rpx;
		padding: 0 32rpx;
		box-sizing: border-box;
		margin-top: 48rpx;
		margin-bottom: 30rpx;

		.VipItem {
			width: 212rpx;
			height: 232rpx;
			border: 1px solid gray;
			display: flex;
			flex-direction: column;
			justify-content: space-evenly;
			align-items: center;
			border-radius: 16rpx;
			position: relative;

			h1 {
				font-weight: bold;
			}

			p {
				color: #DEB365;
				font-size: 50rpx;
			}

			h2 {
				color: gray;
				text-decoration: line-through;
			}

			text {
				width: 98rpx;
				height: 48rpx;
				background: url("../../static/img/tuijian.png");
				text-align: center;
				line-height: 48rpx;
				color: white;
				position: absolute;
				top: -26rpx;
				left: -28rpx;

			}
		}

		.active {
			background-color: #FBF7EF;
		}
	}

	.getVip {
		margin-bottom: 102rpx;

		box-sizing: border-box;

		.top {
			display: flex;
			margin-bottom: 34rpx;
			margin-left: 46rpx;

			h1 {
				width: 92rpx;
				height: 42rpx;
				background: url("../../static/img/gongxi.png");
				text-align: center;
				line-height: 42rpx;
				color: white;
				margin-right: 10rpx;
			}

			text {
				color: #987F51;
			}
		}

		button {
			width: 686rpx;
			height: 80rpx;
			background-color: #FCF1D3;
			color: #B3975D;
			line-height: 80rpx;
		}
	}

	.privilege {
		width: 100%;
		padding-left: 46rpx;

		h1 {
			font-size: 50rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}

		.item {
			display: flex;
			margin-bottom: 50rpx;

			.item-img {
				width: 90rpx;
				height: 90rpx;
				margin-right: 90rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.item-msg {
				flex-grow: 1;
				border-bottom: 1px solid ghostwhite;

				h2 {
					font-size: 30rpx;
				}

				p {
					font-size: 24rpx;
				}
			}
		}
	}

	.explain {
		padding-left: 46rpx;
		padding-bottom: 42rpx;
		box-sizing: border-box;

		h1 {
			font-size: 40rpx;
			font-weight: bold;
		}

		p {
			font-size: 24rpx;
			color: gray;
		}
	}
	.module{
		width: 100%;
		height: 560rpx;
		padding: 22rpx 26rpx 0 26rpx;
		box-sizing: border-box;
		text-align: center;
		background-color: white;
		position: relative;
		h1{
			// margin: 0 auto;
			color: gray;
		}
		.news{
			font-size: 20rpx;
		}
		.close{
			position: absolute;
			top: 22rpx;
			left: 34rpx;
		}
	}
</style>
